
function DOMBuilder(container,extender){
	this.container = container;
	this.extender = extender || false;
}

DOMBuilder.prototype = {
	cache:false,
	constructor:DOMBuilder,
	toString:function(){
		return "DOMBuilder";
	},
	setAttribute:function(node,attr){
		for(var a in attr){
			node.setAttribute(this.getAttribute(a), attr[a]);
		}
	},
	getAttribute:function(a){
		var attr=this.constructor.ATTRIBUTES;
		return attr.hasOwnProperty(a) ? attr[a] : a;
	},
	render:function(container){
		if(!this.container){
			this.container=(container||document.body);
		}
		this[(this.cache.id || this.cache.className || this.cache.nodeName)] = this.cache;
		return this.container.appendChild(this.cache);
	}
};



DOMBuilder.SYNTAX=["A","ABBR","ACRONYM","ADDRESS","BLOCKQUOTE","BR","BUTTON","CITE","CODE","DD","DEL","DFN","DIV","DL","DT","EM",
			"FIELDSET","FORM","H1","H2","H3","H4","H5","H6","HR","IMG","INPUT","INS","LABEL","LEGEND","LI","OL",
			"OPTION","P","PRE","SELECT","SPAN","STRONG","SUB","SUP","TEXTAREA","UL"];

DOMBuilder.NODE = function(){
	arguments.shift = Array.prototype.shift;
	var o = document.createElement(arguments.shift()), id="";
	if(this.extender){
		var z;
		for(z in this.extender){
			o[z]=this.extender[z];
		}
	}
	for(var i=0,n;n = arguments[i];i++){
		if(n.nodeType)
		{
			o.appendChild(n);
			id = (n.id || n.className || n.nodeName);
			if(o[id]){
				if(o[id] instanceof Array){
					o[id].push(n);
				}else{
					o[id] = [o[id],n];
				}
			}else{
				o[id] = n;
			}
		}
		else if(typeof(n) == "string")
		{
			o.appendChild(document.createTextNode(n));
		}
		else if(n instanceof Object)
		{
			this.setAttribute(o,n);
		}
	}
	return this.cache=o;
}

DOMBuilder.INIT = function(){
	for(var i=0,e;e=this.SYNTAX[i]; i++){
		this.prototype[e] = function(){
			arguments.unshift = Array.prototype.unshift;
			arguments.unshift(arguments.callee.nodeName);
			return this.constructor.NODE.apply(this,arguments);
		}
		this.prototype[e].nodeName = e.toLowerCase();
	}
	return true;
}

if(window.attachEvent){
	DOMBuilder.ATTRIBUTES = {
		"class":"className",
		"for":"htmlFor",
		"style":"cssText"
	};
}else{
	DOMBuilder.ATTRIBUTES = {};
}

DOMBuilder.INIT();


/* 
	----------------------------------------------------------
	ATUAL
	----------------------------------------------------------
	 var d = compono.DOMBuilder;
		var x = d.DIV(
					"Teste",
					d.A({href:"http://www.terra.com.br"},
						"LINK", d.STRONG("Terra")
					),
					{className:"menu"}
				);
		document.body.appendChild(x);
 */
 
 /*
 	----------------------------------------------------------
	FUTURO
	----------------------------------------------------------
	var d = new compono.DOMBuilder();
	d.DIV("Teste",d.A({href:"http://www.terra.com.br"}, "LINK ", d.STRONG("Terra")),{className:"menu"});
	d.render();
	
 	var d = new compono.DOMBuilder();
	d.SELECT(
		{op1:val1},
		{op2:val2},
		{op3:val3},
		{op4:val4}
	);
	<select>
		<option value="op1">val1</option>
		<option value="op2">val2</option>
		<option value="op3">val3</option>
		<option value="op4">val4</option>
	</select>
	
	
	d.UL(
		"text1",
		"text2",
		"text3",
		"text4",
	)
	<ul>
		<li>text1</li>
		<li>text2</li>
		<li>text3</li>
		<li>text4</li>
	</ul>
	
	d.LIST(
		{"text1",
		"text2",
		"text3",
		"text4",
	)
	<ul>
		<li>text1</li>
		<li>text2</li>
		<li>text3</li>
		<li>text4</li>
	</ul>	
	
	d.render();

 */